<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * SimplyPost
 *
 * @author		Pascal Kriete
 * @package		SimplyPost
 * @copyright	Copyright (c) 2008, Pascal Kriete
 * @license 	http://www.gnu.org/licenses/lgpl.txt
 */

// ------------------------------------------------------------------------

/**
 * Home Controller
 *
 * @package		SimplyPost
 * @subpackage	Home
 * @category	Controller
 * @author		Pascal Kriete
 */

class Home extends BaseController {

	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function Home()
	{
		parent::BaseController();
		$this->lang->load('home');
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Show all categories with subforums
	 *
	 * @access	public
	 */
	function index()
	{		
		set_title($this->lang->line('home_title'));
		$this->breadcrumb->custom();

		$this->load->helper('date');

		$this->load->model('Cat_model', 'Category');
		$cats = $this->Category->get_all();
		
		if ($cats == FALSE)
		{
			$this->parser->parse('home/all_empty');
		}
		else
		{
			$this->load->model('For_model', 'Forum');
						
			$tmp = array();
			
			// Figure out inner forums
			foreach($cats as $key => $category)
			{
				$tmp = $this->Forum->get_forums($category['id']);
				$cats[$key]['forums'] = array();
				
				// Change keys
				if ($tmp[0] != -1)
				{
					$cats[$key]['empty'] = 0;
								
					foreach($tmp as $row)
					{
						$row_tmp = array();
						foreach($row as $old_key => $val)
						{
							$row_tmp['f_'.$old_key] = $val;
						}
					
						$cats[$key]['forums'][] = $row_tmp;
						$tmp2[] = $row_tmp;
					}
				}
				else
				{
					$cats[$key]['emtpy'] = 1;
				}
			}
			
			$data['categories'] = $cats;
			
			$this->parser->parse('home/home', $data);
		}
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Password hashing test function - LEAVE COMMENTED!
	 *
	 * @access	public
	 *
	function pass_gen()
	{
		ob_start();
		echo '<h3>Your password hash:</h3>';
		echo secure_password('EMAIL', 'PASSWORD');
		
		echo '<h3>The current unix time:</h3>';
		echo time();
		
		$output =& load_class('Output');
		$output->append_output(ob_get_contents());
		@ob_end_clean();
	}
	*/
}